package com.example.bottomnavigationkotlin.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.bottomnavigationkotlin.R
import com.example.bottomnavigationkotlin.model.FuncItem

class FuncAdapter(
    private val items: List<FuncItem>,
    private val onItemClick: (FuncItem) -> Unit
) : RecyclerView.Adapter<FuncAdapter.FuncViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FuncViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_func, parent, false)
        return FuncViewHolder(view)
    }

    override fun onBindViewHolder(holder: FuncViewHolder, position: Int) {
        holder.bind(items[position])
    }

    override fun getItemCount() = items.size

    inner class FuncViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        private val icon = itemView.findViewById<ImageView>(R.id.iv_func_icon)
        private val name = itemView.findViewById<TextView>(R.id.tv_func_name)
        fun bind(item: FuncItem) {
            icon.setImageResource(item.iconRes)
            name.text = item.name
            itemView.setOnClickListener { onItemClick(item) }
        }
    }
} 